package com.yh.utils.extract.jdbcTemplet;

import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

import java.io.InputStream;

@Component
@Slf4j
public class CreateHandler {

    private static String path="/script/datasource.sql";
    @Autowired
    @Qualifier("defaultJdbcTemplate")
    JdbcTemplate jdbcTemplate;

    public void createTable(){
        StringBuffer out = new StringBuffer();
        try {
            InputStream input=getClass().getResourceAsStream(path);
            byte[] b = new byte[4096];
            for (int n; (n = input.read(b)) != -1;) {
                out.append(new String(b, 0, n));
            }
            input.close();
        }catch (Exception e){
            e.printStackTrace();
        }
        try {
            jdbcTemplate.execute(out.toString());
        }catch (Exception e){
            log.info("表已经存在了");
        }


    }
}
